//
//  YTStashDetailsViewController.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/11/13.
//

#import "YTStashDetailsViewController.h"
#import "MCScrollView.h"
#import "YTStashListModel.h"
#import "YTStashDetailsTableViewCell.h"
#import "YTStashRecordsOutListViewController.h"

@interface YTStashDetailsViewController ()
@property (nonatomic ,strong) YTStashListModel * model;
@end

@implementation YTStashDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.shutDownBack = YES;
    
    [self.view addSubview:self.tableview];
    self.tableview.backgroundColor = KcolorHex(@"#EBEDF0");
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.offset(0);
    }];
    MJWeakSelf
    
    [self addFooterView:^{
        [weakSelf.tableview.mj_footer endRefreshingWithNoMoreData];
    }];
    
    
    UIImageView * backimg = kimageView(@"black_path");
    backimg.addClickBlock(^{
        [weakSelf back];
    });
    [self.view addSubview:backimg];
    [backimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(kwt(33));
        make.left.offset(kwt(15));
        make.top.offset(KTop + kwt(15));
    }];
 
    if([UserInfoModel shared].userIdentity == 3){///管理员无出库记录
        UILabel * jl = [DTKTool labelWithText:@"出库记录" andFont:kCFont(18) andTextColor:UIColor.whiteColor];
        jl.backgroundColor = [UIColor colorWithWhite:0 alpha:0.44];
        jl.textAlignment = NSTextAlignmentCenter;
        jl.addClickBlock(^{
            YTStashRecordsOutListViewController * vc = [YTStashRecordsOutListViewController new];
            [weakSelf.navigationController pushViewController:vc animated:YES];
        });
        [DTKTool YJ:kwt(4) andView:jl];
        [self.view addSubview:jl];
        [jl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(kwt(-15));
            make.width.offset(kwt(93));
            make.height.offset(kwt(34));
            make.top.equalTo(backimg);
        }];
    }
    
    
    [self loadNewData];
    
}
- (void)loadNewData{
    [self.view showBusyHUD];
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    
    [dict setObject:self.ID forKey:@"id"];
    [SCNetManger warehouseManageDetailWithDict:dict andCompetionHandlerBlock:^(HTTPDicBase * model) {
        [self.view hideBusyHUD];
        if(model.code == 200){
            self.model = [YTStashListModel yy_modelWithDictionary:model.result];
            [self.tableview.mj_footer endRefreshing];
            [self.tableview reloadData];
        } else {
            [self.view showWarning:model.message];
        }
    }];
    
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    MCScrollView * scrollView = [[MCScrollView alloc] initWithFrame:CGRectMake(0, 0, KSCREEN_WIDTH, kwt(375))];
//    scrollView.indexBack = ^(NSInteger pageIndex) {
//        NSLog(@"=========%zd", pageIndex);
//    };
    if(self.model){
        scrollView.imageArray = [self.model.productImg componentsSeparatedByString:@","];
    }
  
    scrollView.duration = 3.0;
    return scrollView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if(self.model){
        return kwt(375);
    }
    return 0;
}
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(self.model){
        return 1;
    }
    return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return self.model.DetailsCellH;
}

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
   
    YTStashDetailsTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"YTStashDetailsTableViewCell"];
    if (cell == nil) {
        cell = [[YTStashDetailsTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YTStashDetailsTableViewCell"];
    }
    cell.model = self.model;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
}
- (void)setupView{
  
}
@end
